package sort

import (
	"fmt"
	"sort"
)

var trueCount int = 0

func TestSort() {
	nums := []int{}
	res := []int{}

	order := []int{10, 34, 73, 25, 6, 58, 69, 37}
	sort.Ints(order)

	fmt.Println("1 bubble sort:")
	nums = []int{10, 34, 73, 25, 6, 58, 69, 37}
	fmt.Println("before:", nums)
	BubbleSort(nums)
	fmt.Println("after:", nums)
	fmt.Println("equal:", judge(nums, order))
	fmt.Println()

	fmt.Println("2 select sort:")
	nums = []int{10, 34, 73, 25, 6, 58, 69, 37}
	fmt.Println("before:", nums)
	SelectSort(nums)
	fmt.Println("after:", nums)
	fmt.Println("equal:", judge(nums, order))
	fmt.Println()

	fmt.Println("3 insertion sort:")
	nums = []int{10, 34, 73, 25, 6, 58, 69, 37}
	fmt.Println("before:", nums)
	SelectSort(nums)
	fmt.Println("after:", nums)
	fmt.Println("equal:", judge(nums, order))
	fmt.Println()

	fmt.Println("4 shell sort:")
	nums = []int{10, 34, 73, 25, 6, 58, 69, 37}
	fmt.Println("before:", nums)
	ShellSort(nums)
	fmt.Println("after:", nums)
	fmt.Println("equal:", judge(nums, order))
	fmt.Println()

	fmt.Println("5 Merge sort:")
	nums = []int{10, 34, 73, 25, 6, 58, 69, 37}
	fmt.Println("before:", nums)
	res = MergeSort(nums)
	fmt.Println("after:", res)
	fmt.Println("equal:", judge(res, order))
	fmt.Println()

	fmt.Println("6 Quick sort:")
	nums = []int{10, 34, 73, 25, 6, 58, 69, 37}
	fmt.Println("before:", nums)
	QuickSort(nums)
	fmt.Println("after:", nums)
	fmt.Println("equal:", judge(nums, order))
	fmt.Println()

	fmt.Println("7 Heap sort:")
	nums = []int{10, 34, 73, 25, 6, 58, 69, 37}
	fmt.Println("before:", nums)
	HeapSort(nums)
	fmt.Println("after:", nums)
	fmt.Println("equal:", judge(nums, order))
	fmt.Println()

	fmt.Println("8 Count sort:")
	nums = []int{10, 34, 73, 25, 6, 58, 69, 37}
	fmt.Println("before:", nums)
	res = CountSort(nums)
	fmt.Println("after:", res)
	fmt.Println("equal:", judge(res, order))
	fmt.Println()

	fmt.Println("9 Bucket sort:")
	nums = []int{10, 34, 73, 25, 6, 58, 69, 37}
	fmt.Println("before:", nums)
	BucketSort(nums)
	fmt.Println("after:", nums)
	fmt.Println("equal:", judge(nums, order))
	fmt.Println()

	fmt.Println("10 Radix sort:")
	nums = []int{10, 34, 73, 25, 6, 58, 69, 37}
	fmt.Println("before:", nums)
	RadixSort(nums)
	fmt.Println("after:", nums)
	fmt.Println("equal:", judge(nums, order))
	fmt.Println()

	fmt.Println("true count:", trueCount)

}

func judge(s1, s2 []int) bool {
	if len(s1) != len(s2) {
		return false
	}

	for i := range s1 {
		if s1[i] != s2[i] {
			return false
		}
	}

	trueCount++
	return true
}
